#Title[ZtO̎O]
#Text[v[iEJbTp]
#PlayLevel[EXTRA]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main {
	#include_function ".\lib\yuyuko.dnh"

	let name = "Ztu@Ȃsׂiv̍ɂ͍bȂv";

	let xIni = cx;
	let yIni = GetClipMinY + 120;

	sub onInitialize {
		CutIn(YOUMU, name, bossCut, 1, 1, 463, 655);
		SetScore(3000000);
		SetLife(2000);
		SetTimer(65);
		SetDamageRate(20, 20);
		back = CSD ~ "img\back2.png";

		TMain;
		TRate;
	}

	sub onMainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 24);
		yield;
	}

	sub onDrawLoop {
	}

	sub onFinalize {
		DeleteGraphic(bossImg);
		createItems(ITEM_SCORE, 24, 64);
	}

/////////////////////////////////////////////////////////////////////

	task TMain {
		getReady(120);

		loop {
			SetAction(ACT_SHOT_B, 999999);
			createShot;
			wait(300);
			moveToPlayer(rand(40, 80), rand(-20, 20), 30, 32, 32, 32, 152);
		}
	}

	task TRate {
		let rate = 20;
		loop {
			wait(300);
			rate += 5;
			SetDamageRate(rate, rate);
		}
	}

	sub createShot {
		let angle = rand(0, 360);
		let way = 18;
		let span = 360 / way;

		loop(way) {
			shot(angle);
			angle += span;
		}

		task shot(_angle) {
			let obj = createObjShot_(GetX, GetY, 0.7, _angle, RING, rand_int(0, 7), 3);
			ObjShot_SetBombResist(obj, true);

			loop {
				if(!isInScreen(Obj_GetX(obj), Obj_GetY(obj))) {
					alternative(isInScreen2(Obj_GetX(obj), Obj_GetY(obj)))
					case(1, 2) {
						Obj_SetAngle(obj, 0 - (Obj_GetAngle(obj) + 90) - 90);
					}
					case(3, 4) {
						Obj_SetAngle(obj, 0 - Obj_GetAngle(obj));
					}
					others {}
				}
				yield;
			}
		}
	}
	#include_function ".\lib\ZtObody.dnh"
}